package com.atguigu05._super.exer3;

/**
 * ClassName: CheckAccount
 * Package: com.atguigu05._super.exer3
 * Description:
 *
 * @Author ZY
 * @Create 21:43
 * @Version 1.0
 */
public class CheckAccount extends Account{

    private double overdraft;//透支限额

    public CheckAccount(int id, double balance, double annualInterestRate){
        super(id, balance, annualInterestRate);
    }

    public CheckAccount(int id, double balance, double annualInterestRate,double overdraft){
        super(id, balance, annualInterestRate);
        this.overdraft = overdraft;
    }

    public double getOverdraft() {
        return overdraft;
    }

    public void setOverdraft(double overdraft) {
        this.overdraft = overdraft;
    }

    /**
     * 针对于可透支的账户的取钱的操作
     * @param amount 取款金额
     */
    public void withdraw(double amount){
        if(getBalance() >= amount){//如果余额够，从余额取
            //错误的，因为getBalance()本身是获取一个值，而不是一个变量
//            getBalance() = getBalance() - amount;

            //正确的
            super.withdraw(amount);
        } else if (getBalance() + overdraft >= amount) {//如果余额不够，但透支额度够，则从透支额度中取
            overdraft -= amount - getBalance();//先扣余款，再扣可透支额度
            super.withdraw(getBalance());//再从余额中取完(即清零)
        }else{
            System.out.println("超过可透支限额");
        }
    }
}
